<template>
	<view>
		<!-- 收银台 -->
		<view class="edgeInsetTop"></view>
		<view class="wanl-pay">
			<view class="price-box">
				<text class="text-df">{{order_no}}</text>
				<text class="wanl-pip text-price margin-top-sm">{{price}}</text>
			</view>
			<view class="list-box">
				<view class="item">
					<text ></text>
					<view class="action">
						 <text class="title wanl-pip">可用TAST支付</text> 
						<view >
							<text  v-if="isscore">可用TAST {{score}}</text>
							<text v-else>TAST不足，可用TAST {{score}}</text> 
						</view>
						
					</view>
					<view class="radio text-xxl" @tap="onSelect('0')" v-if="isscore">
						<text v-if="select==0" class="wlIcon-xuanze-danxuan wanl-orange"></text>
						<text v-else class="wlIcon-xuanze wanl-gray-light"></text>
					</view>
					<view class="radio text-xxl" v-else>
						<text class="wlIcon-xuanze-danxuan wanl-gray-light"></text>
					</view>
				</view>
				<view class="item">
					<text ></text>
					<view class="action">
						 <text class="title wanl-pip">合并支付({{scbl}}%锁仓TAST，{{100-scbl}}%现金)</text> 
						<view >
							<text  v-if="islockscore">锁仓TAST {{lockscore}}</text>
							<text v-else>锁仓TAST不足，可用锁仓TAST {{lockscore}}</text>
						</view>
						
					</view>
					<view class="radio text-xxl" @tap="onSelect('1')"  v-if="islockscore">
						<text v-if="select==1" class="wlIcon-xuanze-danxuan wanl-orange"></text>
						<text v-else class="wlIcon-xuanze wanl-gray-light"></text>
					</view>
					<view class="radio text-xxl" v-else>
						<text class="wlIcon-xuanze-danxuan wanl-gray-light"></text>
					</view>
					<!-- <view class="radio text-xxl" >
						<text class="wlIcon-xuanze-danxuan wanl-gray-light"></text>
					</view> -->
				</view>
			</view>
			<view v-if="disabled">
				<button class="mix-btn wanl-bg-redorange"> <text class="wlIcon-jiazai wlIconfont-spin margin-right-xs"></text>正在支付中... </button>
			</view>
			<view v-else>
				<button v-if="payNum == 1" class="mix-btn wanl-bg-redorange" @tap="confirm()"> 确认支付 </button>
				<button v-else class="mix-btn wanl-bg-redorange" @tap="confirm()"> 合并支付 </button>
			</view>
			<!-- <view class="footer text-center">
				<view class="text-sm" v-if="order_pay_no">{{order_type === 'groups' ? '拼团':''}}交易号：{{order_pay_no}}</view>
				<view> © 微加速支付</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
				token: '',
				disabled: false,
				price:'0.00',
				isbalance: false,
				order_type: 'goods',
				isscore: false,
				islockscore: false,
				order_no: '',
				order_pay_no: '',
				payNum: 1, // 支付方式 独立支付-合并支付
				payList: [],
				select:'',
				lockscore:'0',
				score:'0',
				ordercode:'',
				scbl:''
			}
		},
		computed: {
			...mapState(['user'])
		},
		// watch: {
		// 	price(val, newval) {
		// 		if(val <= parseFloat(this.$store.state.user.money)){
		// 			this.isbalance = true;
		// 			// this.getPayment();
		// 		}
		// 	}
		// },
		onLoad(option) {
			this.ordercode=option.data;
			this.$api.post({
				url: '/wanlshop/product/getBalance?ordercode='+option.data,
				
				success: res => {
					this.price=res.price;
					this.lockscore=res.lockscore,
					this.score=res.score;
					this.scbl=res.scbl
					if(this.price <= parseFloat(this.score)){
								this.isscore = true;
								// this.getPayment();
								this.select=0;
					}
					if(this.price*this.scbl/100 <= parseFloat(this.lockscore)){
										this.islockscore = true;
										this.select=1;
										// this.getPayment();
					}
					console.log(this.islockscore);
					//this.$store.commit('user/setUserInfo',);
					// 获取支付列表
					//this.getPayment();
				}
			});
			
		},
		methods: {
		
			
			//确认支付
			confirm() {
			
				
					this.disabled = true;
					// 获取小程序code
					// #ifdef MP
					// uni.login({
					//     success: (e) => {
					// 		this.wanlPay(data, e.code);
					//     },
					//     fail: (e) => {
					//         uni.showModal({
					//             content: "无法获取微信code,原因为: " + e.errMsg,
					//             showCancel: false
					//         })
					//     }
					// })
					// // #endif
					// // #ifndef MP
					// // 如果是公众号获取code
					// this.wanlPay(data);
					// // #endif
					this.$api.post({
						url: '/wanlshop/product/payment',
						data: {
							type: this.select,
							ordercode: this.ordercode
						},
						success: res => {
							if(this.select==0){
								this.paySuccess();
							}else{
							this.$jssdk.wxpay({
								data: res,
								success: e => {
									this.paySuccess();
								},
								fail: err => {
									if (err.errMsg == "chooseWXPay:ok") {
										this.$wanlshop.msg('支付成功');
									}else if (err.errMsg == "chooseWXPay:cancel") {
										this.$wanlshop.msg('支付失败，取消支付');
									}else if (err.errMsg == "chooseWXPay:fail") {
										this.$wanlshop.msg('支付失败');
									}
								}
							})
							}
							}
							})
				
			},
			
			onSelect(key){
				this.select=key;
				
			},
			// 支付成功
			paySuccess(){
				this.disabled = false;
				if(this.order_type === 'exchange'){
					this.$store.commit('statistics/order', {
						pay: this.$wanlshop.bcsub(this.$store.state.statistics.order.pay, this.payNum),
						delive: this.$wanlshop.bcadd(this.$store.state.statistics.order.delive, this.payNum)
					});
				}
				this.$wanlshop.to(`/pages/page/success?type=pay&order_type=${this.order_type ? this.order_type:'goods'}`);
			}
		}
	}
</script>

<style>
	page{
		background-color: white;
	}
	radio-group {
	    display: block;
	}
</style>
